package de.bomzhi.mz.pflection.views;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import com.powerflasher.fdt.core.outermodel.IClassModel;
import com.powerflasher.fdt.core.outermodel.IFunctionModel;
import com.powerflasher.fdt.core.outermodel.IInterfaceModel;
import com.powerflasher.fdt.core.outermodel.INamespaceModel;
import com.powerflasher.fdt.core.outermodel.IOuterModelElement;
import com.powerflasher.fdt.core.outermodel.IVariableModel;
import com.powerflasher.fdt.core.outermodel.MetaDataTagModel;
import com.powerflasher.fdt.core.outermodel.PackageModel;
import com.powerflasher.fdt.core.outermodel.SWCModel;
import com.powerflasher.fdt.core.outermodel.SourceFolderModel;
import com.powerflasher.fdt.ui.FDTPluginImages;
import com.powerflasher.fdt.ui.util.SWTResourceUtil;

public class PflectionLabelProvider extends LabelProvider {


	public String getText(Object element) {
		if(element instanceof IOuterModelElement){
			return ((IOuterModelElement) element).getName();
		}
		return "unknown element";
	}
	
	public Image getImage(Object element) {
		if(!(element instanceof IOuterModelElement)){
			return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
		}
		ImageDescriptor descriptor = createImage((IOuterModelElement)element);
		if (descriptor == null)
			return null;
		Image image = SWTResourceUtil.getImageTable().get(descriptor);
		if (image == null) {
			image = descriptor.createImage();
			SWTResourceUtil.getImageTable().put(descriptor, image);
		}
		return image;
	}

	private ImageDescriptor createImage(IOuterModelElement element) {
		if(element instanceof SourceFolderModel)
			return FDTPluginImages.SOURCE_FOLDER;
		else if(element instanceof SWCModel)
			return FDTPluginImages.SWC_LIBRARY;
		else if(element instanceof PackageModel)
			return FDTPluginImages.PACKAGE_FOLDER;
		else if(element instanceof IClassModel)
			return FDTPluginImages.CLASS_ICON;
		else if(element instanceof IInterfaceModel)
			return FDTPluginImages.INTERFACE_ICON;
		else if(element instanceof IFunctionModel)
			return FDTPluginImages.AS_FILE_FUNCTION;
		else if(element instanceof IVariableModel)
			return FDTPluginImages.AS_FILE_VARIABLE;
		else if(element instanceof INamespaceModel)
			return FDTPluginImages.NAMESPACE_ICON;
		else if(element instanceof MetaDataTagModel)
			return FDTPluginImages.SPECIAL_METATAG_ICON;
		return FDTPluginImages.AS_FILE;
	}

}
